package service;

import dao.PageOperation;
import dao.UserOperation;
import utils.JdbcUtils;
import pojo.PageBean;
import pojo.User;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author fire'ge
 */
public class PageService {

    public static PageBean<User> getPageList(int start , int rows) throws SQLException, IOException {
        Connection connection = JdbcUtils.getConnection();
        ResultSet resultSet = UserOperation.checkUser(start, rows,connection);
        List<User> users = new ArrayList<>();
        while (resultSet.next()){
            User user = new User(resultSet.getInt(1)
                    , resultSet.getString(2)
                    , resultSet.getString(3),
                    resultSet.getInt(4));
            users.add(user);
        }
        resultSet.close();
        //获取记录
          ResultSet resultSet1 = PageOperation.checkPage("tb_user",connection);
        int page = 0;
        //test
        while(resultSet1.next()){
            page = resultSet1.getInt(1);
        }
        resultSet1.close();
        PageBean<User> userPageBean = new PageBean<>();
        userPageBean.setPage(page);
        userPageBean.setList(users);
        connection.close();
        return userPageBean;
    }
}
